package com.shanks.home;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.shanks.home.module.android.AndroidActivity;
import com.shanks.home.module.anim.AnimationActivity;
import com.shanks.home.module.component.ComponentActivity;
import com.shanks.home.module.grammar.GrammarActivity;
import com.shanks.home.module.image.ImageActivity;
import com.shanks.home.module.io.IOActivity;
import com.shanks.home.module.media.MediaActivity;
import com.shanks.home.module.model.DataActivity;
import com.shanks.home.module.multythread.MultyThreadActivity;
import com.shanks.home.module.ui.UIActivity;
import com.shanks.home.net.NetworkActivity;
import com.shanks.home.util.DeviceUtil;
import com.shanks.home.util.LogUtil;

/**
 * @author Shanks
 * @time 2013.11.25
 */
public class MainActivity extends Activity {

	private static final String TAG = MainActivity.class.getSimpleName();
	
	private Button uiBtn, networkBtn, mediaBtn, grammarBtn, multyThreadBtn, animationBtn, ioBtn, androidBtn,
					componentBtn, imageBtn, dataBtn;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		DeviceUtil.init(this);
		
		initView();
	}
	
	private void initView() {
		uiBtn = (Button)this.findViewById(R.id.main_ui_btn);
		networkBtn = (Button)this.findViewById(R.id.main_network_btn);
		mediaBtn = (Button)this.findViewById(R.id.main_media_btn);
		grammarBtn = (Button)this.findViewById(R.id.main_grammar_btn);
		multyThreadBtn = (Button)this.findViewById(R.id.main_multy_thread_btn);
		animationBtn = (Button)this.findViewById(R.id.main_animation_btn);
		ioBtn = (Button)this.findViewById(R.id.main_io_btn);
		androidBtn = (Button)this.findViewById(R.id.main_android_btn);
		componentBtn = (Button)this.findViewById(R.id.main_component_btn);
		imageBtn = (Button)this.findViewById(R.id.main_image_btn);
		dataBtn = (Button)this.findViewById(R.id.main_data_btn);
		
		uiBtn.setOnClickListener(onClickListener);
		networkBtn.setOnClickListener(onClickListener);
		mediaBtn.setOnClickListener(onClickListener);
		grammarBtn.setOnClickListener(onClickListener);
		multyThreadBtn.setOnClickListener(onClickListener);
		animationBtn.setOnClickListener(onClickListener);
		ioBtn.setOnClickListener(onClickListener);
		androidBtn.setOnClickListener(onClickListener);
		componentBtn.setOnClickListener(onClickListener);
		imageBtn.setOnClickListener(onClickListener);
		dataBtn.setOnClickListener(onClickListener);
	}

	private OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			int id = v.getId();
			if (id == R.id.main_ui_btn) {
				// Activity使用Bundle传递数据
				Intent intent = new Intent(MainActivity.this, UIActivity.class);
				Bundle bundle = new Bundle();
				bundle.putString("shanks", "activity_bundle_data");
				intent.putExtras(bundle);
				startActivity(intent);
			} else if (id == R.id.main_network_btn) {
				startActivity(new Intent(MainActivity.this, NetworkActivity.class));
			} else if (id == R.id.main_media_btn) {
				startActivity(new Intent(MainActivity.this, MediaActivity.class));
			} else if (id == R.id.main_grammar_btn) {
				startActivity(new Intent(MainActivity.this, GrammarActivity.class));
			} else if (id == R.id.main_multy_thread_btn) {
				startActivity(new Intent(MainActivity.this, MultyThreadActivity.class));
			} else if (id == R.id.main_animation_btn) {
				startActivity(new Intent(MainActivity.this, AnimationActivity.class));
			} else if (id == R.id.main_io_btn) {
				startActivity(new Intent(MainActivity.this, IOActivity.class));
			} else if (id == R.id.main_android_btn) {
				startActivity(new Intent(MainActivity.this, AndroidActivity.class));
			} else if (id == R.id.main_component_btn) {
				startActivity(new Intent(MainActivity.this, ComponentActivity.class));
			} else if (id == R.id.main_image_btn) {
				startActivity(new Intent(MainActivity.this, ImageActivity.class));
			} else if (id == R.id.main_data_btn) {
				startActivity(new Intent(MainActivity.this, DataActivity.class));
			}

		}
	};
	
	/**
	 * 返回键
	 */
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		LogUtil.i(TAG, "click back btn.");
	}
}
